home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / LTimeDateControl 1.0 / LTimeDateControl.h < prev    next >
Encoding:
Text File  |  1995-12-09  |  6.8 KB  |  209 lines  |  [TEXT/CWIE]

  1. //
  2. //    LTimeDateControl v1.0
  3. //        A time and date picker for Power Plant.
  4. //
  5. //    Copyright © 1995 by Michael F. Kamprath
  6. //        mailto:kamprath@kagi.com
  7. //        http://www.leonardo.net/kamprath/claireware.html
  8. //
  9. //    Abstract
  10. //    --------
  11. //
  12. //    LTimeDateControl is a drop in module to give your Power Plant based application an
  13. //    easy to use, graphical time and/or date picker. The user interface of LTimeDateControl
  14. //    allows a user to click on a portion of a date and/or time string, and then change it's
  15. //    value by clicking on an arrow or with the arrow keys.
  16. //
  17. //    ConOps
  18. //    ------
  19. //
  20. //    To use, add a LControl pane to a view in your application and make it's class ID 'TmDt'.
  21. //    Fill out it's values as you would a normal LControl with the following exceptions:
  22. //
  23. //        1.     Min, Max, and Initial vlaue of the LControl is ignored. LTimeDateControl does
  24. //            not use LControl's value tracking mechanism.
  25. //
  26. //        2.    The user constant must be set to the variation of the LTimeDateControl you wish
  27. //            to use. Variation IDs are:
  28. //
  29. //                    Type                |    ID
  30. //                    ===========================
  31. //                    Time only            |    1
  32. //                    Long Date only        |    2
  33. //                    Long Date & Time    |    3
  34. //                    Short Date only        |    4    (not supported yet in v1.0)
  35. //                    Short Date & Time    |    5    (not supported yet in v1.0)
  36. //
  37. //        3.    You may set a text traits ID for LTimeDateControl, but you must ensure the 
  38. //            frame you define for LTimeDateControl is at least the font's height plu 5 pixels
  39. //            and an appropiate width to contain the date/time string plus 20 pixels in
  40. //            width. Some expirementation will probably be needed to get the look you want.
  41. //
  42. //    LTimeDateControl ignores LControl's value tracking mechanism in favor of it's
  43. //    own. You may track a LTimeDateControl's value in either seconds (unsigned long)
  44. //    or by a DateTimeRec. You may get the current value of LTimeDateControl with:
  45. //
  46. //            Uint32            LTimeDateControl::GetDateTimeValue( void )
  47. //            DateTimeRec        LTimeDateControl::GetDateTimeRec( void )
  48. //
  49. //    And set the current value with:
  50. //
  51. //            void            LTimeDateControl::SetDateTimeValue( const Uint32& inValue )
  52. //            void            LTimeDateControl::SetDateTimeValue( const DateTimeRec& inRec )
  53. //    
  54. //    When ever the user changes a LTimeDateControl value (note, not when it is 
  55. //    programatically changed), LTimeDateControl broadcasts a msg_TimeDateHasChanged
  56. //    message (defined in LTimeDateControl.h) to any LListener's attached to the
  57. //    LTimeDateControl. In the ioParameter of the message, the LTimeDateControl's pane 
  58. //    ID is passed.
  59. //
  60. //    LTimeDateControl inherits off of LCommander (along with LControl) so that it will
  61. //    de-hilite the currently selected date portion when it is no longer "in focus" and
  62. //    to get keyDown messages. 
  63. //
  64. //    LTimeDateControl utilizes a StOffscreenGWorld so that a "smooth" redraw will be done.
  65. //    Be sure to include the PowerPlant file "UGWorld.cp" in your project. LTimeDateControl
  66. //    honors it's parent view's background color where appropiate (ensure that a call to
  67. //    ApplyForeAndBackColors() will properly set it at the time of LTimeDateControl redraw).
  68. //
  69. //    Be sure to also include the file LTimeDateControl.rsrc in your project. It contains
  70. //    the control's arrow icons. Of course, you can change them to maintain your "look and feel"
  71. //
  72. //    Legalisms
  73. //    ---------
  74. //
  75. //    You may freely use LTimeDateControl with the following exceptions:
  76. //
  77. //        1.    If you use LTimeDateControl in your project, e-mail me so that I can keep you
  78. //            posted when I release new versions.
  79. //        2.    If you use LTimeDateControl in a project that you release to the public and 
  80. //            charge money for, I ask for a free & registered version of the product.
  81. //        3.    No derivatives of LTimeDateControl may be publicly release with out my consent.
  82. //
  83.  
  84. #ifndef    __LTIMEDATECONTROL__
  85.     #define __LTIMEDATECONTROL__
  86.     
  87. #include <LControl.h>
  88. #include <LCommander.h>
  89.  
  90. class LTimeDateControl    :    public LControl,
  91.                             public LCommander
  92. {
  93. public:
  94.     // public enums
  95.     
  96.     typedef enum
  97.     {
  98.         kTimeVariation = 1,
  99.         kLongDateVariation = 2,
  100.         kLongDateAndTimeVariation = 3,
  101.         kShortDateVariation = 4,
  102.         kShortDateAndTimeVariation = 5
  103.     } ETimeDateControlType;
  104.  
  105.     enum
  106.     {
  107.         kNoPart                = 0x0000,
  108.         
  109.         kArrowPartMask        = 0x00FF,
  110.         kInUpArrow             = 0x0002,
  111.         kInDownArrow         = 0x0004,
  112.         
  113.         kTextComponentMask    = 0xFF00,
  114.         kDateHiliteMask        = 0x0F00,
  115.         kTimeHiliteMask        = 0XF000,
  116.         
  117.         kMonthItem            = 0x0100,
  118.         kDateItem            = 0x0200,
  119.         kYearItem            = 0x0300,
  120.         kDayOfWeekItem        = 0x0400,
  121.         kHourItem            = 0x1000,
  122.         kMinuteItem            = 0x2000,
  123.         kSecondItem            = 0x3000,
  124.         kAMPMItem            = 0x4000
  125.         
  126.     };
  127.     
  128.     enum { class_ID = 'TmDt' };
  129.     
  130.     // the functions
  131.     
  132.     static LTimeDateControl*    CreateTimeDateControlStream(    LStream    *inStream);
  133.     
  134.                         LTimeDateControl();
  135.                         LTimeDateControl(    const LTimeDateControl &inOriginal);
  136.                         LTimeDateControl(    const SPaneInfo &inPaneInfo,
  137.                                             MessageT inValueMessage, 
  138.                                             Uint32 inValue,
  139.                                             ETimeDateControlType inVariation );
  140.                         LTimeDateControl(    LStream *inStream);
  141.     virtual                ~LTimeDateControl();
  142.  
  143.     // Custom Value Trackking
  144.     
  145.     Uint32                GetDateTimeValue( void ) const;
  146.     void                SetDateTimeValue( const Uint32& inValue );
  147.     DateTimeRec            GetDateTimeRec( void ) const;
  148.     void                SetDateTimeValue( const DateTimeRec& inRec );
  149.     
  150.     // Power Plant Support
  151.     
  152.     virtual Boolean        FocusDraw();
  153.     virtual void        DrawSelf();
  154.     
  155.     virtual void        ClickSelf(const SMouseDownEvent &inMouseDown);
  156.  
  157.     virtual Boolean        HandleKeyPress( const EventRecord    &inKeyEvent);
  158.  
  159. protected:
  160.     virtual void        ActivateSelf();
  161.     virtual void        DeactivateSelf();
  162.  
  163.     virtual void        BeTarget();
  164.     virtual void        DontBeTarget();
  165.  
  166.     virtual Int16        FindHotSpot(Point inPoint);
  167.     virtual void        HotSpotAction(Int16 inHotSpot, Boolean inCurrInside, Boolean inPrevInside);
  168.     virtual void        HotSpotResult(Int16 inHotSpot);
  169.     
  170. private:
  171.     void                InitDateTimeControl( void );
  172.     void                InitDateStarts( void );
  173.  
  174.     void                DrawDateTimeControl( const Uint16& theHotSpot = 0 );
  175.  
  176.     Int16                DrawTimeString(    const Point& startPos, 
  177.                                         const Rect& strRect,
  178.                                         const Uint16& hilite );
  179.     Int16                DrawLongDateString(    const Point& startPos, 
  180.                                             const Rect& strRect,
  181.                                             const Uint16& hilite );
  182.     
  183.     
  184.     Uint16                TestTimeString( const Rect& strRect, const Point& hitPt, Int16& width  );
  185.     Uint16                TestLongDateString( const Rect& strRect, const Point& hitPt, Int16& width  );
  186.     
  187.     void                ArrowAction( Uint16 inHotSpot, Boolean holdClick );
  188.     
  189.     ETimeDateControlType            mVariation;
  190.     Uint32                            mDateTimeValue;
  191.     Uint32                            mLastClickTickCount;
  192.     Intl0Hndl                        mTimeFormatH;
  193.     Intl1Hndl                        mDateFormatH;
  194.     Uint16                            mCurrentHilite;    
  195.     ResIDT                            mCntlTextTraitsID;
  196.     Int16                            mStartArray[4], 
  197.                                     mEndArray[4];     /* Array posistions
  198.                                                      *
  199.                                                      *    0 - date num     - Hour
  200.                                                      *    1 - Day Name     - Minute
  201.                                                      *    2 - Month        - AM/PM
  202.                                                      *    3 - year
  203.                                                      */    
  204. };
  205.  
  206. const    MessageT    msg_TimeDateHasChanged        =    10002;  // send this panelID as param
  207.  
  208. #endif
  209.